package com.sright.bcard.cms.controller;

import com.sright.bcard.common.service.share.dto.pager.Pager;
import com.sright.bcard.common.service.share.mvcresolver.BodyFiled;
import com.sright.bcard.common.service.share.mvcresolver.EnableLoginAuth;
import com.sright.bcard.common.service.share.dto.content.FeedbackDto;
import com.sright.bcard.content.share.service.FeedbackService;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: lumf
 * Date: 2020/8/13 6:02 PM
 */
@RestController
@Slf4j
public class FeedbackManageController {
    @Autowired
    private FeedbackService feedbackService;

    @GetMapping("/feedback/list")
    @EnableLoginAuth
    public SrightResponse getFeedbackList(@RequestParam(value = "nickname", required = false) String wxNickName,
                                           @RequestParam(value = "status", required = false) Integer usefulStatus,
                                           @RequestParam(value = "begin_time", required = false) Long beginTime,
                                           @RequestParam(value = "end_time", required = false) Long endTime,
                                           @RequestParam(value = "page") Integer pageIndex,
                                           @RequestParam(value = "pageSize")Integer pageSize
                                          ) {

        log.info("getFeedbackList+");
        Pager<FeedbackDto> pager = feedbackService.getFeedbackList(pageIndex, pageSize,
                wxNickName, usefulStatus,
                beginTime, endTime
                );
        return SrightResponse.defaultSuccess(pager);
    }

    @PostMapping("/feedback/edit")
    @EnableLoginAuth
    public SrightResponse editFeedback(@BodyFiled(value = "id") Long feedbackId,
                                          @BodyFiled(value = "status") Integer usefulStatus
    ) {

        boolean success = feedbackService.updateStatus(feedbackId, usefulStatus);
        if (success) {
            return SrightResponse.defaultSuccess();
        }
        return SrightResponse.defaultBusinessError("编辑出错");
    }
}
